//二叉树的最近公共祖先
public class code5 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(root==null) return null;
        if(p==root||q==root) return root;
        TreeNode Left = lowestCommonAncestor(root.left, p, q);
        TreeNode Right =lowestCommonAncestor(root.right, p, q);
        if(Left != null&&Right!=null) {
            return root;
        } else if(Left != null) {
            return Left;
        } else{
            return Right;
        }
    }
}
